<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
    <el-form-item label="年度" prop="year">
      <el-input v-model="dataForm.year" placeholder="年度"></el-input>
    </el-form-item>
    <el-form-item label="部门名称" prop="lxDeptName">
      <el-input v-model="dataForm.lxDeptName" placeholder="部门名称"></el-input>
    </el-form-item>
    <el-form-item label="部门编号" prop="lxDeptCode">
      <el-input v-model="dataForm.lxDeptCode" placeholder="部门编号"></el-input>
    </el-form-item>
    <el-form-item label="人员编号" prop="lxUserCode">
      <el-input v-model="dataForm.lxUserCode" placeholder="人员编号"></el-input>
    </el-form-item>
    <el-form-item label="人员名称" prop="lxUserName">
      <el-input v-model="dataForm.lxUserName" placeholder="人员名称"></el-input>
    </el-form-item>
    <el-form-item label="人员职务" prop="lxUserZw">
      <el-input v-model="dataForm.lxUserZw" placeholder="人员职务"></el-input>
    </el-form-item>
    <el-form-item label="人员职级" prop="lxUserZj">
      <el-input v-model="dataForm.lxUserZj" placeholder="人员职级"></el-input>
    </el-form-item>
    <el-form-item label="年度得分" prop="yearDf">
      <el-input v-model="dataForm.yearDf" placeholder="年度得分"></el-input>
    </el-form-item>
    <el-form-item label="考核结果" prop="yearJd">
      <el-input v-model="dataForm.yearJd" placeholder="考核结果"></el-input>
    </el-form-item>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button>
      <el-button @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import {getObj, addObj, putObj} from '@/api/jiangjin/jiangjinjgdfb'

    export default {
    data () {
      return {
        visible: false,
        canSubmit: false,
        dataForm: {
          id: 0,
          year: '',
          lx: '',
          lxDeptId: '',
          lxDeptName: '',
          lxDeptCode: '',
          lxUserCode: '',
          lxUserName: '',
          lxUserId: '',
          lxUserZw: '',
          lxUserZj: '',
          yearDf: '',
          yearDfY: '',
          yearJd: '',
          yearJgY: '',
          lxXs: '',
          createTime: '',
          editTime: '',
          createDeptId: '',
          createDeptName: '',
          createUserId: '',
          createUserName: '',
          editDeptId: '',
          editDeptName: '',
          editUserId: '',
          editUserName: '',
          dataState: '',
          deptId: '',
          tenantId: ''
        },
        dataRule: {
          year: [
            { required: true, message: '年度不能为空', trigger: 'blur' }
          ],
          lxDeptName: [
            { required: true, message: '部门名称不能为空', trigger: 'blur' }
          ],
          lxDeptCode: [
            { required: true, message: '部门编号不能为空', trigger: 'blur' }
          ],
          lxUserCode: [
            { required: true, message: '人员编号不能为空', trigger: 'blur' }
          ],
          lxUserName: [
            { required: true, message: '人员名称不能为空', trigger: 'blur' }
          ],
          // lxUserZw: [
          //   { required: true, message: '人员职务不能为空', trigger: 'blur' }
          // ],
          // lxUserZj: [
          //   { required: true, message: '人员职级不能为空', trigger: 'blur' }
          // ],
          // yearDf: [
          //   { required: true, message: '年度得分不能为空', trigger: 'blur' }
          // ],
          // yearDfY: [
          //   { required: true, message: '年度得分原不能为空', trigger: 'blur' }
          // ],
          // yearJd: [
          //   { required: true, message: '考核结果不能为空', trigger: 'blur' }
          // ],
          // yearJgY: [
          //   { required: true, message: '考核结果原不能为空', trigger: 'blur' }
          // ]

        }
      }
    },
    methods: {
      init (id,row) {
        this.dataForm.id = id || 0;
        this.visible = true;
        this.canSubmit = true;
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          this.dataForm = row ;
          // if (this.dataForm.id) {
          //   getObj(this.dataForm.id).then(response => {
          //       this.dataForm = response.data.data
          //   })
          // }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.canSubmit = false;
            if (this.dataForm.id) {
                putObj(this.dataForm).then(data => {
                    this.$notify.success('修改成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                }).catch(() => {
                    this.canSubmit = true;
                });
            } else {
                addObj(this.dataForm).then(data => {
                    this.$notify.success('添加成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                }).catch(() => {
                    this.canSubmit = true;
                });
            }
          }
        })
      }
    }
  }
</script>
